﻿package stuff3D.objects.primitives
{
	import flash.geom.Point;
	import flash.geom.Vector3D;
	import stuff3D.meshes.Triangle;
	import stuff3D.meshes.Mesh;
	
	public class Cube extends Mesh
	{	
		private var R:Number;
		
		public function Cube():void 
		{
			R = 150;
			
			vertices = new Vector.<Vector3D>(8,true);
			vertices[0] = new Vector3D( R, R, R );
			//vertices[1] = new Vector3D( R, R,-R );
			vertices[1] = new Vector3D( 0,0,0 );
			vertices[2] = new Vector3D( R,-R, R );
			vertices[3] = new Vector3D( R, -R, -R );
			vertices[4] = new Vector3D( -R, R, R );
			vertices[5] = new Vector3D(-R, R,-R );
			vertices[6] = new Vector3D(-R,-R, R );
			vertices[7] = new Vector3D(-R,-R,-R );

			// les points uv de la texture pour y placer les triangles
			
			uvdots = new Vector.<Point>(12, true);
			uvdots[0] = new Point( 0,0 );
			uvdots[1] = new Point( 0.33,0 );
			uvdots[2] = new Point( 0.66,0 );
			uvdots[3] = new Point( 1,0 );
			uvdots[4] = new Point( 0, .5 );
			uvdots[5] = new Point( 0.33, .5 );
			uvdots[6] = new Point( 0.66, .5 );
			uvdots[7] = new Point( 1, .5 );
			uvdots[8] = new Point( 0, 1 );
			uvdots[9] = new Point( 0.33, 1 );
			uvdots[10] = new Point( 0.66, 1 );
			uvdots[11] = new Point( 1, 1 );
			
			/*
			 * TriangleCulling.POSITIVE :
			 * clockwise order triangle -> positive normal value -> points to z-axis direction -> away from camera -> not rendered with TriangleCulling.POSITIVE !
			 * */
			
			// les triangles 3D du mesh

			triangles = new Vector.<Triangle>(12,true);
			triangles[0] = new Triangle( 0, 1, 3, 5, 4, 0 );
			triangles[1] = new Triangle( 3, 2, 0, 0, 1, 5 );
			triangles[2] = new Triangle( 1, 5, 7, 6, 5, 1 );
			triangles[3] = new Triangle( 7, 3, 1, 1, 2, 6 );
			triangles[4] = new Triangle( 5, 4, 6, 7, 6, 2 );
			triangles[5] = new Triangle( 6, 7, 5, 2, 3, 7 );
			triangles[6] = new Triangle( 4, 0, 2, 9, 8, 4 );
			triangles[7] = new Triangle( 2, 6, 4, 4, 5, 9 );
			triangles[8] = new Triangle( 2, 3, 7, 10, 9, 5 );
			triangles[9] = new Triangle( 7, 6, 2, 5, 6, 10 );
			triangles[10] = new Triangle( 5, 1, 0, 6, 7, 11 );
			triangles[11] = new Triangle( 4, 5, 0, 10, 6, 11 );
		}
		/*
		override public function get info():String
		{
			var s:String = "";
			s += nb_dots_largeur + file_delimiter1;
			s += nb_dots_hauteur + file_delimiter1;
			for each( var mDot:Vector3D in vertices ) s += mDot.y + file_delimiter2;
			return s;
		}
		override public function set info(s:String):void
		{
			var arrayFile:Array = s.split( file_delimiter1 );
			nb_dots_largeur = arrayFile[ 0 ];
			nb_dots_hauteur = arrayFile[ 1 ];
			populate( arrayFile[ 2 ].split( file_delimiter2 ) );
		}
		*/
	}
}